﻿// SquareLine LVGL GENERATED FILE
// EDITOR VERSION: SquareLine Studio 1.0.5
// LVGL VERSION: 8.2
// PROJECT: SquareLine_Project

#include "ui.h"
#include "ui_helpers.h"


///////////////////// VARIABLES ////////////////////
lv_obj_t* ui_LoadScr;
lv_obj_t* ui_LoadPanel;
lv_obj_t* ui_LoadingBar;
lv_obj_t* ui_Image1;
lv_obj_t* ui_Authorlbls;
lv_obj_t* ui_xiaohuangya;
lv_timer_t* bartimer;
///////////////////// TEST LVGL SETTINGS ////////////////////
// static void set_temp(void* bar, int32_t temp);
// static void set_temp(void* bar, int32_t temp)
// {
//     lv_bar_set_value(bar, temp, LV_ANIM_ON);
// }
void my_timer(lv_timer_t* timer)
{
    /*Use the user_data*/
    static int  processing = 0;
    processing += 10;
    if (processing>50)
    {
        processing = 0;
        lv_timer_pause(bartimer);
        return;
    }
    else
    {
        lv_bar_set_value(ui_LoadingBar, 50 + processing, LV_ANIM_ON);
    }
    
}



///////////////////// ANIMATIONS ////////////////////

// ui_EloAnimation0
// FUNCTION HEADER
void loadingimg_Animation(lv_obj_t* TargetObject, int delay);

// FUNCTION
void loadingimg_Animation(lv_obj_t* TargetObject, int delay)
{

    //
    lv_anim_t PropertyAnimation_0;
    lv_anim_init(&PropertyAnimation_0);
    lv_anim_set_time(&PropertyAnimation_0, 800);
    lv_anim_set_user_data(&PropertyAnimation_0, TargetObject);
    lv_anim_set_custom_exec_cb(&PropertyAnimation_0, _ui_anim_callback_set_y);
    lv_anim_set_values(&PropertyAnimation_0, 0, 120);
    lv_anim_set_path_cb(&PropertyAnimation_0, lv_anim_path_linear);
    lv_anim_set_delay(&PropertyAnimation_0, delay + 0);
    lv_anim_set_early_apply(&PropertyAnimation_0, true);
    lv_anim_set_get_value_cb(&PropertyAnimation_0, &_ui_anim_callback_get_y);
    lv_anim_start(&PropertyAnimation_0);

    //
    lv_anim_t PropertyAnimation_1;
    lv_anim_init(&PropertyAnimation_1);
    lv_anim_set_time(&PropertyAnimation_1, 1000);
    lv_anim_set_user_data(&PropertyAnimation_1, TargetObject);
    lv_anim_set_custom_exec_cb(&PropertyAnimation_1, _ui_anim_callback_set_image_angle);
    lv_anim_set_values(&PropertyAnimation_1, 0, 3600);
    lv_anim_set_path_cb(&PropertyAnimation_1, lv_anim_path_linear);
    lv_anim_set_delay(&PropertyAnimation_1, delay + 800);
    lv_anim_set_early_apply(&PropertyAnimation_1, false);
    lv_anim_set_get_value_cb(&PropertyAnimation_1, &_ui_anim_callback_get_image_angle);
    lv_anim_start(&PropertyAnimation_1);


    //
// lv_anim_t a;
// lv_anim_init(&a);
// lv_anim_set_exec_cb(&a, set_temp);
// lv_anim_set_time(&a, 2000);
// lv_anim_set_var(&a, ui_LoadingBar);
// lv_anim_set_values(&a, 0, 100);
// lv_anim_set_delay(&a, delay + 0);
// lv_anim_set_early_apply(&a, false);
// lv_anim_set_path_cb(&a, lv_anim_path_linear);
// lv_anim_start(&a);

}


///////////////////// FUNCTIONS ////////////////////
static void ui_event_LoadScr(lv_event_t* e)
{
    lv_event_code_t event = lv_event_get_code(e);
    lv_obj_t* ta = lv_event_get_target(e);
    if (event == LV_EVENT_SCREEN_LOAD_START) {
        //_ui_bar_increment(ui_LoadingBar, 100, LV_ANIM_ON)
        loadingimg_Animation(ui_Image1, 0);
        lv_bar_set_value(ui_LoadingBar, 50, LV_ANIM_ON);
        // lv_gif_restart(ui_xiaohuangya);
    }
}

///////////////////// SCREENS ////////////////////
void ui_LoadScr_screen_init(void)
{

    // ui_LoadScr

    ui_LoadScr = lv_obj_create(NULL);

    lv_obj_clear_flag(ui_LoadScr, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_SCROLL_ELASTIC |
        LV_OBJ_FLAG_SCROLL_MOMENTUM);

    lv_obj_add_event_cb(ui_LoadScr, ui_event_LoadScr, LV_EVENT_ALL, NULL);

    // ui_LoadPanel

    ui_LoadPanel = lv_obj_create(ui_LoadScr);

    lv_obj_set_width(ui_LoadPanel, 320);
    lv_obj_set_height(ui_LoadPanel, 240);

    lv_obj_set_x(ui_LoadPanel, 0);
    lv_obj_set_y(ui_LoadPanel, 0);

    lv_obj_set_align(ui_LoadPanel, LV_ALIGN_CENTER);

    lv_obj_clear_flag(ui_LoadPanel, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);

    lv_obj_set_style_radius(ui_LoadPanel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_LoadPanel, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_LoadPanel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_side(ui_LoadPanel, LV_BORDER_SIDE_NONE, LV_PART_MAIN | LV_STATE_DEFAULT);

    // ui_LoadingBar

    ui_LoadingBar = lv_bar_create(ui_LoadScr);
    lv_bar_set_range(ui_LoadingBar, 0, 100);

    lv_obj_set_width(ui_LoadingBar, 250);
    lv_obj_set_height(ui_LoadingBar, 25);

    lv_obj_set_x(ui_LoadingBar, 0);
    lv_obj_set_y(ui_LoadingBar, -20);

    lv_obj_set_align(ui_LoadingBar, LV_ALIGN_CENTER);

    lv_obj_clear_flag(ui_LoadingBar, LV_OBJ_FLAG_PRESS_LOCK | LV_OBJ_FLAG_CLICK_FOCUSABLE | LV_OBJ_FLAG_GESTURE_BUBBLE |
        LV_OBJ_FLAG_SNAPPABLE);

    lv_obj_set_style_bg_color(ui_LoadingBar, lv_color_hex(0x71E7C5), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_LoadingBar, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_color(ui_LoadingBar, lv_color_hex(0xB75FAB), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_opa(ui_LoadingBar, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(ui_LoadingBar, 30, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_spread(ui_LoadingBar, 15, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(ui_LoadingBar, 3, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(ui_LoadingBar, 3, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(ui_LoadingBar, 3, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(ui_LoadingBar, 3, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_anim_time(ui_LoadingBar, 500, LV_PART_MAIN | LV_STATE_DEFAULT);

    lv_obj_set_style_bg_color(ui_LoadingBar, lv_color_hex(0xCE7D11), LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_LoadingBar, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT);



    // ui_Image1

    ui_Image1 = lv_img_create(ui_LoadScr);
    lv_img_set_src(ui_Image1, &ui_img_guangzhao_png);

    lv_obj_set_width(ui_Image1, LV_SIZE_CONTENT);
    lv_obj_set_height(ui_Image1, LV_SIZE_CONTENT);

    lv_obj_set_x(ui_Image1, -115);
    lv_obj_set_y(ui_Image1, -140);

    lv_obj_set_align(ui_Image1, LV_ALIGN_CENTER);

    lv_obj_add_flag(ui_Image1, LV_OBJ_FLAG_ADV_HITTEST);
    lv_obj_clear_flag(ui_Image1, LV_OBJ_FLAG_SCROLLABLE);

    // ui_Authorlbls

    ui_Authorlbls = lv_label_create(ui_LoadScr);

    lv_obj_set_width(ui_Authorlbls, 180);
    lv_obj_set_height(ui_Authorlbls, 35);

    lv_obj_set_x(ui_Authorlbls, 0);
    lv_obj_set_y(ui_Authorlbls, 50);

    lv_obj_set_align(ui_Authorlbls, LV_ALIGN_CENTER);

    lv_label_set_long_mode(ui_Authorlbls, LV_LABEL_LONG_SCROLL_CIRCULAR);
    lv_label_set_text(ui_Authorlbls, "Author:YYDX");

    lv_obj_set_style_text_color(ui_Authorlbls, lv_color_hex(0xE36122), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(ui_Authorlbls, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_letter_space(ui_Authorlbls, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_line_space(ui_Authorlbls, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(ui_Authorlbls, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui_Authorlbls, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(ui_Authorlbls, 35, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_Authorlbls, lv_color_hex(0x1FD23D), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_Authorlbls, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_color(ui_Authorlbls, lv_color_hex(0x16E8A3), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_opa(ui_Authorlbls, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(ui_Authorlbls, 35, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_spread(ui_Authorlbls, 25, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_left(ui_Authorlbls, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_right(ui_Authorlbls, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_top(ui_Authorlbls, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_pad_bottom(ui_Authorlbls, 0, LV_PART_MAIN | LV_STATE_DEFAULT);


    //

    ui_xiaohuangya = lv_gif_create(ui_LoadScr);
    lv_gif_set_src(ui_xiaohuangya, &xiaohuangya1);
    //lv_obj_center(ui_xiaohuangya);
    lv_obj_align(ui_xiaohuangya, LV_ALIGN_TOP_LEFT, 10, 120);

    bartimer = lv_timer_create(my_timer, 1000, NULL);

}

void ui_init(void)
{
    lv_disp_t* dispp = lv_disp_get_default();
    lv_theme_t* theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
        false, LV_FONT_DEFAULT);
    lv_disp_set_theme(dispp, theme);
    ui_LoadScr_screen_init();
    lv_disp_load_scr(ui_LoadScr);

}

